<?php
if(isset($_GET["CatId"])){

	$sql = "SELECT San_pham.* FROM San_pham,Danh_muc_sp where San_pham.D_Id = Danh_muc_sp.Id and (San_pham.D_Id =".$_GET["CatId"]. " Or Danh_muc_sp.FatherId =".$_GET["CatId"]. " )";
	$products = $mysqli->query($sql);
	if($mysqli->error){
		die("error". $mysqli->error);
	}
	
	
	while ($row = $products->fetch_assoc()) {
		echo "<div class='product_box'>";
		//echo "<div> <a  href='index.php?ProductId=".$row['Id'] . "' >" . $row["Name"] . "</a></div>";	
		echo "<a href ='index.php?ProductId=".$row['Id']."'><img src='".$row['Picture']."' alt='Image error' /></a>";
		echo "<h3>".$row['Name']."</h3>";
		echo "<p class='product_price'>Vui lòng gọi</p>";
		//echo "<a href='Chitiet_sp.php?Sp_Id=".$row['Id']."' class='add_to_card'>Chi tiết sản phẩm</a>";
		echo "<a href='index.php?ProductId=".$row['Id']."' class='add_to_card'>Chi tiết sản phẩm</a>";
		echo "</div>";
	}

}else if(isset($_GET["ProductId"])){

	$sql = "SELECT * FROM San_pham where Id =".$_GET["ProductId"]. " ";
	
	$product = $mysqli->query($sql);
	if($mysqli->error){
		die("error". $mysqli->error);
	}
	
	
	while ($row = $product->fetch_assoc()) {
		echo "<div class='content_half float_r'>
		<table>
		<tr>
		<td height='150' width='500'><center><h4>".$row['Description']."</h4></center></td>
		</tr>
		</table>
		</div>";
		echo "<div class='content_half float_l'>";	
		echo "<a href ='".$row['Picture']."'><img src='".$row['Picture']."' alt='Image error' /></a>";
		echo "<h3><center>".$row['Name']."</center></h3>";
		echo "</div>";
		//echo "<div class = 'content_half float_r'>";
		//echo "<table ><tbody><tr><td width='160' height='150'>";
		//echo "<h3>".$row['Description']."</h3>";
		//echo "</td></tr></tbody></table>";
		//echo "<div>";
// 		echo "<h3>".$row['Name']."</h3>";
// 		echo "<p class='product_price'>Vui lòng gọi</p>";
// 		echo "<div class='mota'>";
// 		echo "<h3>".$row['Description']."</h3>";
// 		echo "</div>";
		
	}

}

?>
